package com.xique.blelock.Adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qmuiteam.qmui.widget.QMUILoadingView;
import com.xique.blelock.Interface.OnItemClickListener;
import com.xique.blelock.R;
import com.xique.blelock.Utils.TimeUtil;
import com.xique.blelock.model.HistoryMessageInfo;
import com.xique.blelock.view.Setting.HuodongActiviy;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/12/7.
 */

public class SystemNotificationAdapter extends Adapter<SystemNotificationAdapter.ViewHolder> {
    private List<HistoryMessageInfo> mDatas = new ArrayList<>();
    private OnItemClickListener onItemClickListener;

    public SystemNotificationAdapter(List<HistoryMessageInfo> bleDevices) {
        this.mDatas.addAll(bleDevices);
    }

    public void setDeviceList(List<HistoryMessageInfo> deviceList){
        this.mDatas.clear();
        this.mDatas.addAll(deviceList);
    }

    @NonNull
    @Override
    public SystemNotificationAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //LayoutInflater.from指定写法
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.xitonggongao, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
//        viewHolder.rootlayout = view.findViewById(R.id.rootlayout);
//        viewHolder.name = view.findViewById(R.id.devname);
        viewHolder.time = view.findViewById(R.id.time);
        viewHolder.title = view.findViewById(R.id.title);
        viewHolder.content = view.findViewById(R.id.content);



        return viewHolder;

    }

    @Override
    public void onBindViewHolder(@NonNull final SystemNotificationAdapter.ViewHolder holder, final int position) {
        HistoryMessageInfo historyMessageInfo = mDatas.get(position);
        holder.time.setText(TimeUtil.getDateStr(Long.parseLong(historyMessageInfo.getTimestamp()),TimeUtil.defaultPattern));
        holder.title.setText(historyMessageInfo.getData().getTitle());
        holder.content.setText(historyMessageInfo.getData().getContent());


    }

    @Override
    public int getItemCount() {
            return mDatas.size();
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(View itemView) {
            super(itemView);
        }


        View rootlayout;
        ImageView lefticon;
        TextView title;
        TextView content;
        TextView time;
        ImageView righticon;
        QMUILoadingView loadingView;

    }
}
